{//产品列表}
<table id='tab' class="easyui-datagrid" data-options="url:'__SELF__',fitColumns:true,singleSelect:true,toolbar:'#tool',pagination:true,">
    <thead>   
        <tr>   
            <th data-options="field:'id',width:'100'">ID</th>               
            <th data-options="field:'name',width:'100'">标题</th>
            <th data-options="field:'images',width:'100'">图片</th> 
            <th data-options="field:'category',width:'100'">类别</th>   
            <th data-options="field:'hit',width:'100'">点击量</th>        
            <th data-options="field:'ctime',width:'100'">添加时间</th>
            <th data-options="field:'utime',width:'100'">修改时间</th>   
           
        </tr>   
    </thead>   
    
</table>  
<div id='tool'>
<a href="{:U('add')}" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加</a>
<a id='editbtn' href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a>
<a id='delbtn'  href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true">删除</a>
<a id='stock'  href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-cut',plain:true">库存</a>
</div>
<script>
$('#editbtn').click(function(){
	
	var row=$('#tab').datagrid('getSelected');//从表格中获取用户选中
	
	if(row){
		//alert(row.username);
		var url="{:U('edit','',false)}"+'/id/'+row.id;
		window.location.href=url;
	}else{
		alert('请先选中一行'); 
	}
	
	
	
});

$('#delbtn').click(function(){
	var row=$('#tab').datagrid('getSelected');//获取用户当前选中的行
	if(row){
		
	$.ajax({
		url:"{:U('del')}",
		data:{id:row.id},
		type:'post',
		dataType:'json',
		success:function(msg){
			if(msg.code==1){
				$('#tab').datagrid('reload');
			}else{
				alert(msg.message);
			}
			
		}
		
	});
		 
	}else{
		alert('请选择一行');
	}
	
});
$('#stock').click(function(){
	
		var row=$('#tab').datagrid('getSelected');//获取用户当前选中的行
		if(row){
			//有选一行
			var id=row.id;
			window.location.href="__MODULE__/stock/index/id/"+id;
			 
		}else{
			alert('请选择一行');
		}
});

$('#delbtn').click(function(){

    var row=$('#tab').datagrid('getSelected');
    if(row){
        if(confirm('您确定要删除吗？')){
            $.ajax({
                url:"{:U('del')}",
                data:{id:row.id},
                type:'post',
                dataType:'json',
                success:function(msg){
                    if(msg.code==1){
                        alert(msg.message);
                        $('#tab').datagrid('reload');
                    }else{
                        alert(msg.message);
                    }
                }
            })
        }
    }else{
        alert('请先选中一行！');
    }
});

</script>